package com.bootdo.collection.controller;

import com.bootdo.collection.domain.PictureSetDO;
import com.bootdo.collection.service.PictureSetService;
import com.bootdo.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@Controller
@RequestMapping("/collection/pictureSet")
public class PictureSetControlller {
    @Autowired
    private PictureSetService pictureSetService;
    private String prefix = "collection/picture";
    @GetMapping()
    public String pictureSet(){
        return prefix + "/picture_set_list";
    }

    /**
     * 查询符合条件的套图
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ResponseBody()
    public PageUtils pictureSetList(@RequestParam Map<String,Object> params){
//        PageBean<PictureSetDO> pageBean = pictureSetService.list(params);
        return pictureSetService.list(params);
    }

    /**
     * 进入套图的详情页
     * @param pictureSetId
     * @param stationId
     * @param keyTitle 伪原创的键
     * @param model
     * @return
     */
    @GetMapping("/detail/{pictureSetId}/{stationId}/{keyTitle}")
    String detail(@PathVariable("pictureSetId") int pictureSetId,@PathVariable("stationId")int stationId,@PathVariable("keyTitle") String keyTitle, Model model) {
        model.addAttribute("pictureSetId",pictureSetId);
        model.addAttribute("stationId",stationId);
        PictureSetDO pictureSetDO = pictureSetService.getPictureSetDOById(pictureSetId);
        model.addAttribute("title",pictureSetDO.getTitle());
        model.addAttribute("uploadStationName",pictureSetDO.getUploadStationName());
        model.addAttribute("keyTitle",keyTitle);
        return prefix + "/picture";
    }

    @GetMapping("/getListByTitle")
    @ResponseBody()
    public PageUtils getListByTitle(@RequestParam  Map<String,Object> params){
        return pictureSetService.getListByTitle(params);
    }

}

